﻿@model link_entity
@{
    ViewData["Title"] = "编辑链接";
}
@section Scripts{
<script>
    layui.use(['colorpicker'], function(){
        var colorpicker = layui.colorpicker
        ,upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test-upload-normal'
            ,url: '/v6admin/upload?module=link'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#test-upload-normal-img').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code == 200) {
                    $("#logo").val(res.data.path);
                    return layer.msg('上传成功');
                }
                else {
                    return layer.msg('上传失败');
                }
                //上传成功
            }
            ,error: function(){

            }
        });

        //表单赋值
        colorpicker.render({
            elem: '#test-colorpicker-dome3'
            ,color: '@Model.font_color'
            ,done: function(color){
                $('#font_color').val(color);
            }
        });
    });

    $(function(){
        $(".imgDiv").mouseenter(function () {
            $(this).find(".delete").show();
        });

        $(".imgDiv").mouseleave(function () {
            $(this).find(".delete").hide();
        });

        $(".delete").on("click",function(){
            if(confirm('确认删除吗？')){
                $.ajax({
                    url: "/v6admin/upload/delete",
                    data:{
                        "module": "link",
                        "source_id": $(this).data("id"),
                        "file_path": $(this).data("file_path"),
                    },
                    success:function(res){
                        alert(res.msg);
                        $("#logo").val("");
                        $('#test-upload-normal-img').attr('src', ""); //图片链接（base64）
                    }
                });
            }
        });
    });
</script>
}
<div class="layui-card">
    <div class="layui-card-header">@ViewData["Title"]</div>
    <div class="layui-card-body" style="padding: 15px;">
        <form asp-action="edit" class="layui-form">
            <input asp-for="id" type="hidden" />
            <div asp-validation-summary="ModelOnly" class="text-danger"></div>

            <div class="layui-form-item">
                <div class="layui-col-md6">
                    <label asp-for="category_id" class="layui-form-label">链接分类</label>
                    <div class="layui-input-block">
                        <select asp-for="category_id" class="layui-input" lay-verify="required" asp-items="ViewBag.category_id"></select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-md6">
                    <label asp-for="title" class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <input asp-for="title" class="layui-input" lay-verify="required" />
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-md6">
                    <label asp-for="logo" class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <div class="layui-upload">
                            <input type="hidden" asp-for="logo" />
                            <button type="button" class="layui-btn" id="test-upload-normal">
                                <i class="layui-icon">&#xe67c;</i>
                                上传图片
                            </button>
                            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                预览图：
                                <div class="layui-upload-list">
                                    <div class="imgDiv">
                                        <img id="test-upload-normal-img" style="max-width: 480px;max-height: 360px;" src="@Model.logo" />
                                        <a href="###" class="delete" data-id="@Model.id" data-file_path="@Model.logo"><i class="layui-icon layui-icon-delete"></i>删除</a>
                                    </div>
                                </div>
                            </blockquote>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-col-md6">
                    <label asp-for="url" class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <input asp-for="url" class="layui-input" />
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-md6">
                    <label asp-for="sort_rank" class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <input asp-for="sort_rank" class="layui-input" />
                    </div>
                </div>
            </div>

            @{
                var font_list = new List<SelectListItem>()
            {
            new SelectListItem() { Text = "标准", Value = "" },
            new SelectListItem() { Text = "粗体", Value = "bold"}
            };
            }
            <div class="layui-form-item">
                <label class="layui-form-label">字体粗细</label>
                <div class="layui-input-block">
                    <v6cms-radio asp-items="@font_list" asp-for="font_weight"></v6cms-radio>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-col-md6">
                    <label asp-for="font_color" class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <div class="layui-input-inline" style="width: 120px;">
                            <input type="text" asp-for="font_color" placeholder="请选择颜色" class="layui-input">
                        </div>
                        <div class="layui-inline" style="left: -11px;">
                            <div id="test-colorpicker-dome3"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-layout-admin">
                <div class="layui-input-block">
                    <div class="layui-footer" style="left: 0;">
                        <button class="layui-btn" lay-submit="" lay-filter="component-form-demo1">保存</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
